import { EditType } from "@/type/BaseEnum"
import { ref } from "vue"
import {addUserApi, deleteUserApi} from "@/api/user";
import {message} from "ant-design-vue";
import useInstance from "@/hooks/useInstance";

export default function useUser(getList:any) {
    const { global } = useInstance()
    //新增弹框属性
    const addRef = ref()
    //新增
    const addBtn = () => {
        addRef.value.show(EditType.ADD)
    }
    //编辑
    const editBtn = (row: any) => {
        addRef.value.show(EditType.EDIT, row)
    }
    //删除
    const deleteBtn = async (row: any) => {
        const confirm = await global.$myConfirm();
        if (confirm) {
            let res = await deleteUserApi(row.userId)
            if (res && res.code == 200) {
                message.success(res.msg)
                getList()
            }
        }
    }
    return {
        addRef,
        addBtn,
        editBtn,
        deleteBtn,
    }
}
